<?php

/**
 * @category controller
 * @name $Options
 * @package admin
 * @author HungPV <phamvanhung0818@gmail.com>
 */
class Options extends MX_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
        $option = new Option();
        $option->get();
        $data['options'] = $option;
        $data['view'] = 'options_index';
        $this->load->view('admin_theme/template', $data);
    }

    function add() {
        if ($this->input->post('key')) {
            $key = $this->input->post('key');
            $value = $this->input->post('value');

            $option = new Option();
            $option->key = $key;
            $option->value = $value;
            $option->save();

            redirect('admin/options');
        }
        $data['view'] = 'options_add';
        $this->load->view('admin_theme/template', $data);
    }

    function edit($id) {
        if ($this->input->post('key')) {
            $key = $this->input->post('key');
            $value = $this->input->post('value');
            $id = $this->input->post('id');

            $option = new Option();
            $option->where('id', $id)->get();
            if ($option->result_count() > 0) {
                $option->key = $key;
                $option->value = $value;
                $option->save();
            }
            redirect('admin/options');
        }
        $option = new Option();
        $option->where('id', $id)->get();
        $data['option'] = $option;

        $data['id'] = $id;
        $data['view'] = 'options_edit';
        $this->load->view('admin_theme/template', $data);
    }
    
    

}
